package com.example.demo.properties.project;

import com.google.common.collect.Lists;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * 软件著作权:王艳明
 * 系统名称:SpringBoot后台管理系统
 *
 * @author WangYanming
 * @ClassName 类:ProjectSettingsModel.java
 * @Description 功能描述:ProjectSettingsModel
 * @Version 1.0
 * @date 2025-10-13 上午 10:34
 */
@Data
public class ProjectSettingsModel {

    private boolean debug;

    private List<ProjectSettingsLogModel> logs;

    public static ProjectSettingsModel mapToObj(Map<String, Object> map) {
        ProjectSettingsModel projectSettingsModel = new ProjectSettingsModel();
        // debug
        boolean debug = (Boolean) map.get("debug");
        projectSettingsModel.setDebug(debug);
        // logs
        List<ProjectSettingsLogModel> logs = Lists.newArrayList();
        Map<String, Map<String, String>> logsMap = (Map<String, Map<String, String>>) map.get("logs");
        for (Map<String, String> logMap : logsMap.values()) {
            ProjectSettingsLogModel projectSettingsLogModel = new ProjectSettingsLogModel();
            for (Map.Entry<String, String> entry : logMap.entrySet()) {
                String key = entry.getKey();
                System.out.println("key:" + key);
                String value = entry.getValue();
                System.out.println("value:" + value);
                if ("type".equals(key)) {
                    projectSettingsLogModel.setType(value);
                } else if ("path".equals(key)) {
                    projectSettingsLogModel.setPath(value);
                }
            }
            logs.add(projectSettingsLogModel);
        }
        // jdk8+
        System.out.println("logsMap.values().forEach(value -> {");
        logsMap.values().forEach(value -> {
            // 只有一行代码时{}可以省略
            System.out.println("value.toString():" + value.toString());
            System.out.println(",");
        });
        System.out.println("});");
        projectSettingsModel.setLogs(logs);
        return projectSettingsModel;
    }

}
